﻿using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.Collections;
using System.Data;
using System.ComponentModel;
using System.Data.OracleClient;
namespace INTEX.DataBase.Tools
{
    public partial class INTEXDBC
    {
        public DataRow Convert2BABST(DataRow dwInput, string AUF, bool IsConvert = false)
        {
            DataSet SResult = new DataSet();
            SResult = QueryABAUFM(dwInput, 0);
            DataRow dwReturn = null;
            if (SResult.Tables[0].Rows.Count > 0)
            {
                dwReturn = SResult.Tables[0].Rows[0];
            }
            else
            {
                dwReturn = SResult.Tables[0].NewRow();
            }
            switch (AUF)
            {
                case "JLT":
                    #region====JLT======
                    dwReturn["BMMANDANT"]="00";
                    dwReturn["BMBAUMKRS"] = "SZ";
                    dwReturn["BMBAUMLFD"] = "000118";
                    dwReturn["BMKART"] = "J4-0003             ";
                    dwReturn["BMKVAR"] = "1 ";
                    dwReturn["BMFARBE"] = "1         ";
                    dwReturn["BMZENSUR"] = " ";
                    dwReturn["BMZUSTAND"] = "    ";
                    dwReturn["BMSCHLICHTGR"] = "     ";
                    dwReturn["BMSCHLICHTNR"] = "000000000000000";
                    dwReturn["BMBAUMKZ"] = "Z";
                    dwReturn["BMVERWEN"] = "S";
                    dwReturn["BMHERART"] = "S";
                    dwReturn["BMFDZ"] = "5634";
                    dwReturn["BMGABED"] = "J";
                    dwReturn["BMKETTTYP"] = "01    ";
                    dwReturn["BMKANTE"] = "  ";
                    dwReturn["BMLO"] = "  ";
                    dwReturn["BMLB"] = "  ";
                    dwReturn["BMLP"] = "        ";
                    dwReturn["BMAUFBKZ"] = " ";
                    dwReturn["BMDATERL"] = "0";
                    dwReturn["BMBEM"] = "                                        ";
                    dwReturn["BMKOLLINR"] = "        ";
                    dwReturn["BMSPSTA"] = "  ";
                    dwReturn["BMSPGRD"] = "  ";
                    dwReturn["BMORGKZ"] = "J";
                    dwReturn["BMLEER"] = " ";
                    dwReturn["BMSOLLKZ"] = "J";
                    dwReturn["BMSOLLLG"] = "21340";
                    dwReturn["BMSOLLGEW"] = "421042";
                    dwReturn["BMSOLLVLG"] = "0";
                    dwReturn["BMSOLLSTK"] = "0";
                    dwReturn["BMISTLG"] = "0";
                    dwReturn["BMISTGEW"] = "0";
                    dwReturn["BMISTVLG"] = "0";
                    dwReturn["BMISTSTK"] = "0";
                    dwReturn["BMRESTLG"] = "0";
                    dwReturn["BMURISTLG"] = "0";
                    dwReturn["BMRESTGEW"] = "0";
                    dwReturn["BMKGNET"] = "0";
                    dwReturn["BMKGBRUT"] = "0";
                    dwReturn["BMTARAI"] = "0";
                    dwReturn["BMTARAA"] = "0";
                    dwReturn["BMAUFKRS"] = "T4";
                    dwReturn["BMAUFLFD"] = "001328";
                    dwReturn["BMAUFPOS"] = "001";
                    dwReturn["BMSA"] = "320";
                    dwReturn["BMAUFTYP"] = "V";
                    dwReturn["BMFERTKZ"] = "E";
                    dwReturn["BMPRODLO"] = "01";
                    dwReturn["BMPRODLB"] = "QZ";
                    dwReturn["BMPRODLP"] = "01      ";
                    dwReturn["BMPRODAUFBKZ"] = " ";
                    dwReturn["BMSPPART"] = "          ";
                    dwReturn["BMPARTIE"] = "0000000";
                    dwReturn["BMPARTIEKZ"] = "0";
                    dwReturn["BMDATVW"] = "0";
                    dwReturn["BMDATDRU"] = "0";
                    dwReturn["BMDATABG"] = "0";
                    dwReturn["BMDATRP"] = "0";
                    dwReturn["BMDATRPM"] = "0";
                    dwReturn["BMDATANG"] = "0";
                    dwReturn["BMDATABWEB"] = "0";
                    dwReturn["BMERSATZKZ"] = " ";
                    dwReturn["BMKOMBIKZ"] = " ";
                    dwReturn["BMANZTB"] = "0";
                    dwReturn["BMBAHNIG"] = "0";
                    dwReturn["BMPICKUP"] = "0";
                    dwReturn["BMABAUMKRS"] = "  ";
                    dwReturn["BMABAUMLFD"] = "000000";
                    dwReturn["BMSTKZL"] = "0";
                    dwReturn["BMBAABGZ"] = " ";
                    dwReturn["BMAPOS"] = "0001";
                    dwReturn["BMRAFOLGE"] = "000";
                    dwReturn["BMAUSFFRB"] = "0";
                    dwReturn["BMTAX"] = "   ";
                    dwReturn["BMSCHIENE"] = "     ";
                    dwReturn["BMMNRKRS"] = "  ";
                    dwReturn["BMMLFDNR"] = "0320";
                    dwReturn["BMMPOS"] = "05";
                    dwReturn["BMMAPOS"] = "00";
                    dwReturn["BMDL"] = " ";
                    dwReturn["BMBEARB"] = "        ";
                    dwReturn["BMZULO"] = "  ";
                    dwReturn["BMZULB"] = "  ";
                    dwReturn["BMZULP"] = "        ";
                    dwReturn["BMZUAUFBKZ"] = " ";
                    dwReturn["BMRART"] = "                    ";
                    dwReturn["BMRVAR"] = "  ";
                    dwReturn["BMRFARBE"] = "          ";
                    dwReturn["BMLIEFNR"] = "        ";
                    dwReturn["BMBESTKZ"] = " ";
                    dwReturn["BMBNRLIEF"] = "          ";
                    dwReturn["BMEGKZ"] = " ";
                    dwReturn["BMLIEFSCHNR"] = "        ";
                    dwReturn["BMLIEFDAT"] = "0";
                    dwReturn["BMRECHNR"] = "          ";
                    dwReturn["BMKLABR"] = " ";
                    dwReturn["BMEINPR"] = "0";
                    dwReturn["BMRECHDAT"] = "0";
                    dwReturn["BMBDEKZ"] = "0";
                    dwReturn["BMJJJJBDE"] = "0";
                    dwReturn["BMBNRBDE"] = "0";
                    dwReturn["BMDATBDE"] = "0000000000";
                    dwReturn["BMBDEBKZ"] = " ";
                    dwReturn["BMJJJJMAT"] = "0";
                    dwReturn["BMBNRMAT"] = "0";
                    dwReturn["BMDATMAT"] = "0";
                    dwReturn["BMISOLLLG"] = "0";
                    dwReturn["BMIISTLG"] = "0";
                    dwReturn["BMIDIFFLG"] = "0";
                    dwReturn["BMIDATUM"] = "0";
                    dwReturn["BMISTATUS"] = " ";
                    dwReturn["BMIJJJJ"] = "0";
                    dwReturn["BMIBELEGNR"] = "0";
                    dwReturn["BMIBPOSVON"] = "0";
                    dwReturn["BMIBPOSBIS"] = "0";
                    dwReturn["BMRODA"] = "0";
                    dwReturn["BMWIND"] = "0";
                    dwReturn["BMVWMNRKRS"] = "  ";
                    dwReturn["BMVWMLFDNR"] = "0000";
                    dwReturn["BMVWMPOS"] = "00";
                    dwReturn["BMMUKZ"] = " ";
                    dwReturn["BMZTERL"] = "    ";
                    dwReturn["BMVERSION"] = "0";
                    dwReturn["BMKGBRUTGW"] = "0";
                    dwReturn["BMFILLER"] = "                                                            ";
                    dwReturn["BMAENDZL"] = "0";
                    dwReturn["BMAENDBEN"] = "        ";
                    dwReturn["BMAENDDAT"] = "0";
                    dwReturn["BMNEUBEN"] = "INTEXE  ";
                    dwReturn["BMNEUDAT"] = "20141009";

                    #endregion
                    break;
                default:
                    break;
            }
            if (IsConvert)
            {
                foreach (DataColumn cm in dwInput.Table.Columns)
                {
                    if (dwInput[cm.ColumnName].ToString() == "")
                        continue;
                    if (dwInput.Table.Columns.Contains(cm.ColumnName))
                    {
                        dwReturn[cm.ColumnName] = dwInput[cm.ColumnName];
                    }
                }
            }
            return dwReturn;
        }
        public void MapBABST(ref DataRow dwLocal, DataRow dwData)
        {
            BlindMap(ref dwLocal, dwData);
        }
        public void SaveBABST(DataRow dwData, string ITXDBVERSION = "JLT")
        {
            DataSet setResult = new DataSet();
            DataTable tbLocal = null;
            DataRow dwLocal = null;
            bool flgExist = false;

            setResult = QueryBABST(dwData);
            if (setResult.Tables.Count > 0)
            {
                tbLocal = setResult.Tables[0];
                if (tbLocal.Rows.Count > 0)
                {
                    flgExist = true;
                    dwLocal = tbLocal.Rows[0];
                }
                else
                {
                    dwLocal = tbLocal.NewRow();
                }
            }

            MapBABST(ref dwLocal, dwData);
            switch (ITXDBVERSION)
            {
                case "JLT":
                    if (!flgExist)
                    {
                        InsertBABST(dwLocal);
                    }
                    UpdateBABST(dwLocal, 1);
                    break;
            }

        }
        public void InsertBABST(DataRow dwData, int option = 1)
        {
            OracleCommand or1;
            or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    or1.CommandText = "INSERT INTO BABST(BMMANDANT, BMBAUMKRS, BMBAUMLFD, BMKART, BMKVAR, BMFARBE, BMZENSUR, BMZUSTAND, BMSCHLICHTGR, BMSCHLICHTNR, BMBAUMKZ, BMVERWEN, BMHERART, BMFDZ, BMGABED, BMKETTTYP, BMKANTE, BMLO, BMLB, BMLP, BMAUFBKZ, BMDATERL, BMBEM, BMKOLLINR, BMSPSTA, BMSPGRD, BMORGKZ, BMLEER, BMSOLLKZ, BMSOLLLG, BMSOLLGEW, BMSOLLVLG, BMSOLLSTK, BMISTLG, BMISTGEW, BMISTVLG, BMISTSTK, BMRESTLG, BMURISTLG, BMRESTGEW, BMKGNET, BMKGBRUT, BMTARAI, BMTARAA, BMAUFKRS, BMAUFLFD, BMAUFPOS, BMSA, BMAUFTYP, BMFERTKZ, BMPRODLO, BMPRODLB, BMPRODLP, BMPRODAUFBKZ, BMSPPART, BMPARTIE, BMPARTIEKZ, BMDATVW, BMDATDRU, BMDATABG, BMDATRP, BMDATRPM, BMDATANG, BMDATABWEB, BMERSATZKZ, BMKOMBIKZ, BMANZTB, BMBAHNIG, BMPICKUP, BMABAUMKRS, BMABAUMLFD, BMSTKZL, BMBAABGZ, BMAPOS, BMRAFOLGE, BMAUSFFRB, BMTAX, BMSCHIENE, BMMNRKRS, BMMLFDNR, BMMPOS, BMMAPOS, BMDL, BMBEARB, BMZULO, BMZULB, BMZULP, BMZUAUFBKZ, BMRART, BMRVAR, BMRFARBE, BMLIEFNR, BMBESTKZ, BMBNRLIEF, BMEGKZ, BMLIEFSCHNR, BMLIEFDAT, BMRECHNR, BMKLABR, BMEINPR, BMRECHDAT, BMBDEKZ, BMJJJJBDE, BMBNRBDE, BMDATBDE, BMBDEBKZ, BMJJJJMAT, BMBNRMAT, BMDATMAT, BMISOLLLG, BMIISTLG, BMIDIFFLG, BMIDATUM, BMISTATUS, BMIJJJJ, BMIBELEGNR, BMIBPOSVON, BMIBPOSBIS, BMRODA, BMWIND, BMVWMNRKRS, BMVWMLFDNR, BMVWMPOS, BMMUKZ, BMZTERL, BMVERSION, BMKGBRUTGW, BMFILLER, BMAENDZL, BMAENDBEN, BMAENDDAT, BMNEUBEN, BMNEUDAT)"
       + " VALUES (:BMMANDANT, :BMBAUMKRS,:BMBAUMLFD, '                    ', '  ', '          ', ' ', '    ', '     ', '000000000000000', 'Z', 'S', 'S', 0, 'J', '      ', '  ', '  ', '  ', '        ', ' ', 0, '                                        ', '        ', '  ', '  ', 'J', ' ', 'J', 20000, 147017, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '  ', '      ', '   ', '320', 'V', 'E', 'TX', 'BB', '010101  ', ' ', '          ', '0000000', '0', 0, 0, 0, 0, 0, 0, 0, ' ', ' ', 0, 0, 0, '  ', '000000', 0, ' ', '0001', '000', 0, '   ', '     ', 'M ', '2001', '01', '00', ' ', '        ', '  ', '  ', '        ', ' ', '                    ', '  ', '          ', '        ', ' ', '          ', ' ', '        ', 0, '          ', ' ', 0, 0, '0', 0, 0, '0000000000', ' ', 0, 0, 0, 0, 0, 0, 0, ' ', 0, 0, 0, 0, 0, 0, '  ', '0000', '00', ' ', '    ', '0', 0, '                                                            ', 0, '        ', 0, '        ', 0)";
                    or1.Parameters.Add("BMMANDANT", OracleType.NVarChar).Value = dwData["BMMANDANT"].ToString();
                    or1.Parameters.Add("BMBAUMKRS", OracleType.NVarChar).Value = dwData["BMBAUMKRS"].ToString();
                    or1.Parameters.Add("BMBAUMLFD", OracleType.NVarChar).Value = dwData["BMBAUMLFD"].ToString();
                    break;
            }
            Connect2Proxy(or1);
        }
        public void DeleteBABST(string client, string krs, string lfd, string pos, int option = 1)
        {
            OracleCommand or1 = OracleDB.CreateCommand();

            switch (option)
            {
                case 1:
                    or1.CommandText = "DELETE BABST "
                + "  WHERE BMMANDANT=:BMMANDANT AND BMAUFKRS=:BMAUFKRS AND BMAUFLFD=:BMAUFLFD AND BMAUFPOS=:BMAUFPOS";
                    or1.Parameters.Add("BMMANDANT", OracleType.NVarChar).Value = client;
                    or1.Parameters.Add("BMAUFKRS", OracleType.NVarChar).Value = krs;
                    or1.Parameters.Add("BMAUFLFD", OracleType.NVarChar).Value = lfd;
                    or1.Parameters.Add("BMAUFPOS", OracleType.NVarChar).Value = pos;
                    break;
                case 2:
                    or1.CommandText = "DELETE BABST "
                + "  WHERE GAMANDANT=:BMMANDANT AND BMAUFKRS=:BMAUFKRS AND BMAUFLFD=:BMAUFLFD ";
                    or1.Parameters.Add("BMMANDANT", OracleType.NVarChar).Value = client;
                    or1.Parameters.Add("BMAUFKRS", OracleType.NVarChar).Value = krs;
                    or1.Parameters.Add("BMAUFLFD", OracleType.NVarChar).Value = lfd;

                    break;
                default:
                    break;
            }
            Connect2Proxy(or1);
        }
        public void UpdateBABST(DataRow dwData, int option = 1)
        {
            OracleCommand or1;
            or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    #region===
                    or1.CommandText = "UPDATE BABST SET "
               + "BMMANDANT=:BMMANDANT,"
               + "BMBAUMKRS=:BMBAUMKRS,"
               + "BMBAUMLFD=:BMBAUMLFD,"
               + "BMKART=:BMKART,"
               + "BMKVAR=:BMKVAR,"
               + "BMFARBE=:BMFARBE,"
               + "BMZENSUR=:BMZENSUR,"
               + "BMZUSTAND=:BMZUSTAND,"
               + "BMSCHLICHTGR=:BMSCHLICHTGR,"
               + "BMSCHLICHTNR=:BMSCHLICHTNR,"
               + "BMBAUMKZ=:BMBAUMKZ,"
               + "BMVERWEN=:BMVERWEN,"
               + "BMHERART=:BMHERART,"
               + "BMFDZ=:BMFDZ,"
               + "BMGABED=:BMGABED,"
               + "BMKETTTYP=:BMKETTTYP,"
               + "BMKANTE=:BMKANTE,"
               + "BMLO=:BMLO,"
               + "BMLB=:BMLB,"
               + "BMLP=:BMLP,"
               + "BMAUFBKZ=:BMAUFBKZ,"
               + "BMDATERL=:BMDATERL,"
               + "BMBEM=:BMBEM,"
               + "BMKOLLINR=:BMKOLLINR,"
               + "BMSPSTA=:BMSPSTA,"
               + "BMSPGRD=:BMSPGRD,"
               + "BMORGKZ=:BMORGKZ,"
               + "BMLEER=:BMLEER,"
               + "BMSOLLKZ=:BMSOLLKZ,"
               + "BMSOLLLG=:BMSOLLLG,"
               + "BMSOLLGEW=:BMSOLLGEW,"
               + "BMSOLLVLG=:BMSOLLVLG,"
               + "BMSOLLSTK=:BMSOLLSTK,"
               + "BMISTLG=:BMISTLG,"
               + "BMISTGEW=:BMISTGEW,"
               + "BMISTVLG=:BMISTVLG,"
               + "BMISTSTK=:BMISTSTK,"
               + "BMRESTLG=:BMRESTLG,"
               + "BMURISTLG=:BMURISTLG,"
               + "BMRESTGEW=:BMRESTGEW,"
               + "BMKGNET=:BMKGNET,"
               + "BMKGBRUT=:BMKGBRUT,"
               + "BMTARAI=:BMTARAI,"
               + "BMTARAA=:BMTARAA,"
               + "BMAUFKRS=:BMAUFKRS,"
               + "BMAUFLFD=:BMAUFLFD,"
               + "BMAUFPOS=:BMAUFPOS,"
               + "BMSA=:BMSA,"
               + "BMAUFTYP=:BMAUFTYP,"
               + "BMFERTKZ=:BMFERTKZ,"
               + "BMPRODLO=:BMPRODLO,"
               + "BMPRODLB=:BMPRODLB,"
               + "BMPRODLP=:BMPRODLP,"
               + "BMPRODAUFBKZ=:BMPRODAUFBKZ,"
               + "BMSPPART=:BMSPPART,"
               + "BMPARTIE=:BMPARTIE,"
               + "BMPARTIEKZ=:BMPARTIEKZ,"
               + "BMDATVW=:BMDATVW,"
               + "BMDATDRU=:BMDATDRU,"
               + "BMDATABG=:BMDATABG,"
               + "BMDATRP=:BMDATRP,"
               + "BMDATRPM=:BMDATRPM,"
               + "BMDATANG=:BMDATANG,"
               + "BMDATABWEB=:BMDATABWEB,"
               + "BMERSATZKZ=:BMERSATZKZ,"
               + "BMKOMBIKZ=:BMKOMBIKZ,"
               + "BMANZTB=:BMANZTB,"
               + "BMBAHNIG=:BMBAHNIG,"
               + "BMPICKUP=:BMPICKUP,"
               + "BMABAUMKRS=:BMABAUMKRS,"
               + "BMABAUMLFD=:BMABAUMLFD,"
               + "BMSTKZL=:BMSTKZL,"
               + "BMBAABGZ=:BMBAABGZ,"
               + "BMAPOS=:BMAPOS,"
               + "BMRAFOLGE=:BMRAFOLGE,"
               + "BMAUSFFRB=:BMAUSFFRB,"
               + "BMTAX=:BMTAX,"
               + "BMSCHIENE=:BMSCHIENE,"
               + "BMMNRKRS=:BMMNRKRS,"
               + "BMMLFDNR=:BMMLFDNR,"
               + "BMMPOS=:BMMPOS,"
               + "BMMAPOS=:BMMAPOS,"
               + "BMDL=:BMDL,"
               + "BMBEARB=:BMBEARB,"
               + "BMZULO=:BMZULO,"
               + "BMZULB=:BMZULB,"
               + "BMZULP=:BMZULP,"
               + "BMZUAUFBKZ=:BMZUAUFBKZ,"
               + "BMRART=:BMRART,"
               + "BMRVAR=:BMRVAR,"
               + "BMRFARBE=:BMRFARBE,"
               + "BMLIEFNR=:BMLIEFNR,"
               + "BMBESTKZ=:BMBESTKZ,"
               + "BMBNRLIEF=:BMBNRLIEF,"
               + "BMEGKZ=:BMEGKZ,"
               + "BMLIEFSCHNR=:BMLIEFSCHNR,"
               + "BMLIEFDAT=:BMLIEFDAT,"
               + "BMRECHNR=:BMRECHNR,"
               + "BMKLABR=:BMKLABR,"
               + "BMEINPR=:BMEINPR,"
               + "BMRECHDAT=:BMRECHDAT,"
               + "BMBDEKZ=:BMBDEKZ,"
               + "BMJJJJBDE=:BMJJJJBDE,"
               + "BMBNRBDE=:BMBNRBDE,"
               + "BMDATBDE=:BMDATBDE,"
               + "BMBDEBKZ=:BMBDEBKZ,"
               + "BMJJJJMAT=:BMJJJJMAT,"
               + "BMBNRMAT=:BMBNRMAT,"
               + "BMDATMAT=:BMDATMAT,"
               + "BMISOLLLG=:BMISOLLLG,"
               + "BMIISTLG=:BMIISTLG,"
               + "BMIDIFFLG=:BMIDIFFLG,"
               + "BMIDATUM=:BMIDATUM,"
               + "BMISTATUS=:BMISTATUS,"
               + "BMIJJJJ=:BMIJJJJ,"
               + "BMIBELEGNR=:BMIBELEGNR,"
               + "BMIBPOSVON=:BMIBPOSVON,"
               + "BMIBPOSBIS=:BMIBPOSBIS,"
               + "BMRODA=:BMRODA,"
               + "BMWIND=:BMWIND,"
               + "BMVWMNRKRS=:BMVWMNRKRS,"
               + "BMVWMLFDNR=:BMVWMLFDNR,"
               + "BMVWMPOS=:BMVWMPOS,"
               + "BMMUKZ=:BMMUKZ,"
               + "BMZTERL=:BMZTERL,"
               + "BMVERSION=:BMVERSION,"
               + "BMKGBRUTGW=:BMKGBRUTGW,"
               + "BMFILLER=:BMFILLER,"
               + "BMAENDZL=:BMAENDZL,"
               + "BMAENDBEN=:BMAENDBEN,"
               + "BMAENDDAT=:BMAENDDAT,"
               + "BMNEUBEN=:BMNEUBEN,"
               + "BMNEUDAT=:BMNEUDAT "
               + " WHERE  "
               + "  BMMANDANT=:BMMANDANT AND BMBAUMKRS=:BMBAUMKRS AND BMBAUMLFD=:BMBAUMLFD";
                    or1.Parameters.Add("BMMANDANT", OracleType.NVarChar).Value = dwData["BMMANDANT"].ToString();
                    or1.Parameters.Add("BMBAUMKRS", OracleType.NVarChar).Value = dwData["BMBAUMKRS"].ToString();
                    or1.Parameters.Add("BMBAUMLFD", OracleType.NVarChar).Value = dwData["BMBAUMLFD"].ToString();
                    or1.Parameters.Add("BMKART", OracleType.NVarChar).Value = dwData["BMKART"].ToString();
                    or1.Parameters.Add("BMKVAR", OracleType.NVarChar).Value = dwData["BMKVAR"].ToString();
                    or1.Parameters.Add("BMFARBE", OracleType.NVarChar).Value = dwData["BMFARBE"].ToString();
                    or1.Parameters.Add("BMZENSUR", OracleType.NVarChar).Value = dwData["BMZENSUR"].ToString();
                    or1.Parameters.Add("BMZUSTAND", OracleType.NVarChar).Value = dwData["BMZUSTAND"].ToString();
                    or1.Parameters.Add("BMSCHLICHTGR", OracleType.NVarChar).Value = dwData["BMSCHLICHTGR"].ToString();
                    or1.Parameters.Add("BMSCHLICHTNR", OracleType.NVarChar).Value = dwData["BMSCHLICHTNR"].ToString();
                    or1.Parameters.Add("BMBAUMKZ", OracleType.NVarChar).Value = dwData["BMBAUMKZ"].ToString();
                    or1.Parameters.Add("BMVERWEN", OracleType.NVarChar).Value = dwData["BMVERWEN"].ToString();
                    or1.Parameters.Add("BMHERART", OracleType.NVarChar).Value = dwData["BMHERART"].ToString();
                    or1.Parameters.Add("BMFDZ", OracleType.NVarChar).Value = dwData["BMFDZ"].ToString();
                    or1.Parameters.Add("BMGABED", OracleType.NVarChar).Value = dwData["BMGABED"].ToString();
                    or1.Parameters.Add("BMKETTTYP", OracleType.NVarChar).Value = dwData["BMKETTTYP"].ToString();
                    or1.Parameters.Add("BMKANTE", OracleType.NVarChar).Value = dwData["BMKANTE"].ToString();
                    or1.Parameters.Add("BMLO", OracleType.NVarChar).Value = dwData["BMLO"].ToString();
                    or1.Parameters.Add("BMLB", OracleType.NVarChar).Value = dwData["BMLB"].ToString();
                    or1.Parameters.Add("BMLP", OracleType.NVarChar).Value = dwData["BMLP"].ToString();
                    or1.Parameters.Add("BMAUFBKZ", OracleType.NVarChar).Value = dwData["BMAUFBKZ"].ToString();
                    or1.Parameters.Add("BMDATERL", OracleType.NVarChar).Value = dwData["BMDATERL"].ToString();
                    or1.Parameters.Add("BMBEM", OracleType.NVarChar).Value = dwData["BMBEM"].ToString();
                    or1.Parameters.Add("BMKOLLINR", OracleType.NVarChar).Value = dwData["BMKOLLINR"].ToString();
                    or1.Parameters.Add("BMSPSTA", OracleType.NVarChar).Value = dwData["BMSPSTA"].ToString();
                    or1.Parameters.Add("BMSPGRD", OracleType.NVarChar).Value = dwData["BMSPGRD"].ToString();
                    or1.Parameters.Add("BMORGKZ", OracleType.NVarChar).Value = dwData["BMORGKZ"].ToString();
                    or1.Parameters.Add("BMLEER", OracleType.NVarChar).Value = dwData["BMLEER"].ToString();
                    or1.Parameters.Add("BMSOLLKZ", OracleType.NVarChar).Value = dwData["BMSOLLKZ"].ToString();
                    or1.Parameters.Add("BMSOLLLG", OracleType.NVarChar).Value = dwData["BMSOLLLG"].ToString();
                    or1.Parameters.Add("BMSOLLGEW", OracleType.NVarChar).Value = dwData["BMSOLLGEW"].ToString();
                    or1.Parameters.Add("BMSOLLVLG", OracleType.NVarChar).Value = dwData["BMSOLLVLG"].ToString();
                    or1.Parameters.Add("BMSOLLSTK", OracleType.NVarChar).Value = dwData["BMSOLLSTK"].ToString();
                    or1.Parameters.Add("BMISTLG", OracleType.NVarChar).Value = dwData["BMISTLG"].ToString();
                    or1.Parameters.Add("BMISTGEW", OracleType.NVarChar).Value = dwData["BMISTGEW"].ToString();
                    or1.Parameters.Add("BMISTVLG", OracleType.NVarChar).Value = dwData["BMISTVLG"].ToString();
                    or1.Parameters.Add("BMISTSTK", OracleType.NVarChar).Value = dwData["BMISTSTK"].ToString();
                    or1.Parameters.Add("BMRESTLG", OracleType.NVarChar).Value = dwData["BMRESTLG"].ToString();
                    or1.Parameters.Add("BMURISTLG", OracleType.NVarChar).Value = dwData["BMURISTLG"].ToString();
                    or1.Parameters.Add("BMRESTGEW", OracleType.NVarChar).Value = dwData["BMRESTGEW"].ToString();
                    or1.Parameters.Add("BMKGNET", OracleType.NVarChar).Value = dwData["BMKGNET"].ToString();
                    or1.Parameters.Add("BMKGBRUT", OracleType.NVarChar).Value = dwData["BMKGBRUT"].ToString();
                    or1.Parameters.Add("BMTARAI", OracleType.NVarChar).Value = dwData["BMTARAI"].ToString();
                    or1.Parameters.Add("BMTARAA", OracleType.NVarChar).Value = dwData["BMTARAA"].ToString();
                    or1.Parameters.Add("BMAUFKRS", OracleType.NVarChar).Value = dwData["BMAUFKRS"].ToString();
                    or1.Parameters.Add("BMAUFLFD", OracleType.NVarChar).Value = dwData["BMAUFLFD"].ToString();
                    or1.Parameters.Add("BMAUFPOS", OracleType.NVarChar).Value = dwData["BMAUFPOS"].ToString();
                    or1.Parameters.Add("BMSA", OracleType.NVarChar).Value = dwData["BMSA"].ToString();
                    or1.Parameters.Add("BMAUFTYP", OracleType.NVarChar).Value = dwData["BMAUFTYP"].ToString();
                    or1.Parameters.Add("BMFERTKZ", OracleType.NVarChar).Value = dwData["BMFERTKZ"].ToString();
                    or1.Parameters.Add("BMPRODLO", OracleType.NVarChar).Value = dwData["BMPRODLO"].ToString();
                    or1.Parameters.Add("BMPRODLB", OracleType.NVarChar).Value = dwData["BMPRODLB"].ToString();
                    or1.Parameters.Add("BMPRODLP", OracleType.NVarChar).Value = dwData["BMPRODLP"].ToString();
                    or1.Parameters.Add("BMPRODAUFBKZ", OracleType.NVarChar).Value = dwData["BMPRODAUFBKZ"].ToString();
                    or1.Parameters.Add("BMSPPART", OracleType.NVarChar).Value = dwData["BMSPPART"].ToString();
                    or1.Parameters.Add("BMPARTIE", OracleType.NVarChar).Value = dwData["BMPARTIE"].ToString();
                    or1.Parameters.Add("BMPARTIEKZ", OracleType.NVarChar).Value = dwData["BMPARTIEKZ"].ToString();
                    or1.Parameters.Add("BMDATVW", OracleType.NVarChar).Value = dwData["BMDATVW"].ToString();
                    or1.Parameters.Add("BMDATDRU", OracleType.NVarChar).Value = dwData["BMDATDRU"].ToString();
                    or1.Parameters.Add("BMDATABG", OracleType.NVarChar).Value = dwData["BMDATABG"].ToString();
                    or1.Parameters.Add("BMDATRP", OracleType.NVarChar).Value = dwData["BMDATRP"].ToString();
                    or1.Parameters.Add("BMDATRPM", OracleType.NVarChar).Value = dwData["BMDATRPM"].ToString();
                    or1.Parameters.Add("BMDATANG", OracleType.NVarChar).Value = dwData["BMDATANG"].ToString();
                    or1.Parameters.Add("BMDATABWEB", OracleType.NVarChar).Value = dwData["BMDATABWEB"].ToString();
                    or1.Parameters.Add("BMERSATZKZ", OracleType.NVarChar).Value = dwData["BMERSATZKZ"].ToString();
                    or1.Parameters.Add("BMKOMBIKZ", OracleType.NVarChar).Value = dwData["BMKOMBIKZ"].ToString();
                    or1.Parameters.Add("BMANZTB", OracleType.NVarChar).Value = dwData["BMANZTB"].ToString();
                    or1.Parameters.Add("BMBAHNIG", OracleType.NVarChar).Value = dwData["BMBAHNIG"].ToString();
                    or1.Parameters.Add("BMPICKUP", OracleType.NVarChar).Value = dwData["BMPICKUP"].ToString();
                    or1.Parameters.Add("BMABAUMKRS", OracleType.NVarChar).Value = dwData["BMABAUMKRS"].ToString();
                    or1.Parameters.Add("BMABAUMLFD", OracleType.NVarChar).Value = dwData["BMABAUMLFD"].ToString();
                    or1.Parameters.Add("BMSTKZL", OracleType.NVarChar).Value = dwData["BMSTKZL"].ToString();
                    or1.Parameters.Add("BMBAABGZ", OracleType.NVarChar).Value = dwData["BMBAABGZ"].ToString();
                    or1.Parameters.Add("BMAPOS", OracleType.NVarChar).Value = dwData["BMAPOS"].ToString();
                    or1.Parameters.Add("BMRAFOLGE", OracleType.NVarChar).Value = dwData["BMRAFOLGE"].ToString();
                    or1.Parameters.Add("BMAUSFFRB", OracleType.NVarChar).Value = dwData["BMAUSFFRB"].ToString();
                    or1.Parameters.Add("BMTAX", OracleType.NVarChar).Value = dwData["BMTAX"].ToString();
                    or1.Parameters.Add("BMSCHIENE", OracleType.NVarChar).Value = dwData["BMSCHIENE"].ToString();
                    or1.Parameters.Add("BMMNRKRS", OracleType.NVarChar).Value = dwData["BMMNRKRS"].ToString();
                    or1.Parameters.Add("BMMLFDNR", OracleType.NVarChar).Value = dwData["BMMLFDNR"].ToString();
                    or1.Parameters.Add("BMMPOS", OracleType.NVarChar).Value = dwData["BMMPOS"].ToString();
                    or1.Parameters.Add("BMMAPOS", OracleType.NVarChar).Value = dwData["BMMAPOS"].ToString();
                    or1.Parameters.Add("BMDL", OracleType.NVarChar).Value = dwData["BMDL"].ToString();
                    or1.Parameters.Add("BMBEARB", OracleType.NVarChar).Value = dwData["BMBEARB"].ToString();
                    or1.Parameters.Add("BMZULO", OracleType.NVarChar).Value = dwData["BMZULO"].ToString();
                    or1.Parameters.Add("BMZULB", OracleType.NVarChar).Value = dwData["BMZULB"].ToString();
                    or1.Parameters.Add("BMZULP", OracleType.NVarChar).Value = dwData["BMZULP"].ToString();
                    or1.Parameters.Add("BMZUAUFBKZ", OracleType.NVarChar).Value = dwData["BMZUAUFBKZ"].ToString();
                    or1.Parameters.Add("BMRART", OracleType.NVarChar).Value = dwData["BMRART"].ToString();
                    or1.Parameters.Add("BMRVAR", OracleType.NVarChar).Value = dwData["BMRVAR"].ToString();
                    or1.Parameters.Add("BMRFARBE", OracleType.NVarChar).Value = dwData["BMRFARBE"].ToString();
                    or1.Parameters.Add("BMLIEFNR", OracleType.NVarChar).Value = dwData["BMLIEFNR"].ToString();
                    or1.Parameters.Add("BMBESTKZ", OracleType.NVarChar).Value = dwData["BMBESTKZ"].ToString();
                    or1.Parameters.Add("BMBNRLIEF", OracleType.NVarChar).Value = dwData["BMBNRLIEF"].ToString();
                    or1.Parameters.Add("BMEGKZ", OracleType.NVarChar).Value = dwData["BMEGKZ"].ToString();
                    or1.Parameters.Add("BMLIEFSCHNR", OracleType.NVarChar).Value = dwData["BMLIEFSCHNR"].ToString();
                    or1.Parameters.Add("BMLIEFDAT", OracleType.NVarChar).Value = dwData["BMLIEFDAT"].ToString();
                    or1.Parameters.Add("BMRECHNR", OracleType.NVarChar).Value = dwData["BMRECHNR"].ToString();
                    or1.Parameters.Add("BMKLABR", OracleType.NVarChar).Value = dwData["BMKLABR"].ToString();
                    or1.Parameters.Add("BMEINPR", OracleType.NVarChar).Value = dwData["BMEINPR"].ToString();
                    or1.Parameters.Add("BMRECHDAT", OracleType.NVarChar).Value = dwData["BMRECHDAT"].ToString();
                    or1.Parameters.Add("BMBDEKZ", OracleType.NVarChar).Value = dwData["BMBDEKZ"].ToString();
                    or1.Parameters.Add("BMJJJJBDE", OracleType.NVarChar).Value = dwData["BMJJJJBDE"].ToString();
                    or1.Parameters.Add("BMBNRBDE", OracleType.NVarChar).Value = dwData["BMBNRBDE"].ToString();
                    or1.Parameters.Add("BMDATBDE", OracleType.NVarChar).Value = dwData["BMDATBDE"].ToString();
                    or1.Parameters.Add("BMBDEBKZ", OracleType.NVarChar).Value = dwData["BMBDEBKZ"].ToString();
                    or1.Parameters.Add("BMJJJJMAT", OracleType.NVarChar).Value = dwData["BMJJJJMAT"].ToString();
                    or1.Parameters.Add("BMBNRMAT", OracleType.NVarChar).Value = dwData["BMBNRMAT"].ToString();
                    or1.Parameters.Add("BMDATMAT", OracleType.NVarChar).Value = dwData["BMDATMAT"].ToString();
                    or1.Parameters.Add("BMISOLLLG", OracleType.NVarChar).Value = dwData["BMISOLLLG"].ToString();
                    or1.Parameters.Add("BMIISTLG", OracleType.NVarChar).Value = dwData["BMIISTLG"].ToString();
                    or1.Parameters.Add("BMIDIFFLG", OracleType.NVarChar).Value = dwData["BMIDIFFLG"].ToString();
                    or1.Parameters.Add("BMIDATUM", OracleType.NVarChar).Value = dwData["BMIDATUM"].ToString();
                    or1.Parameters.Add("BMISTATUS", OracleType.NVarChar).Value = dwData["BMISTATUS"].ToString();
                    or1.Parameters.Add("BMIJJJJ", OracleType.NVarChar).Value = dwData["BMIJJJJ"].ToString();
                    or1.Parameters.Add("BMIBELEGNR", OracleType.NVarChar).Value = dwData["BMIBELEGNR"].ToString();
                    or1.Parameters.Add("BMIBPOSVON", OracleType.NVarChar).Value = dwData["BMIBPOSVON"].ToString();
                    or1.Parameters.Add("BMIBPOSBIS", OracleType.NVarChar).Value = dwData["BMIBPOSBIS"].ToString();
                    or1.Parameters.Add("BMRODA", OracleType.NVarChar).Value = dwData["BMRODA"].ToString();
                    or1.Parameters.Add("BMWIND", OracleType.NVarChar).Value = dwData["BMWIND"].ToString();
                    or1.Parameters.Add("BMVWMNRKRS", OracleType.NVarChar).Value = dwData["BMVWMNRKRS"].ToString();
                    or1.Parameters.Add("BMVWMLFDNR", OracleType.NVarChar).Value = dwData["BMVWMLFDNR"].ToString();
                    or1.Parameters.Add("BMVWMPOS", OracleType.NVarChar).Value = dwData["BMVWMPOS"].ToString();
                    or1.Parameters.Add("BMMUKZ", OracleType.NVarChar).Value = dwData["BMMUKZ"].ToString();
                    or1.Parameters.Add("BMZTERL", OracleType.NVarChar).Value = dwData["BMZTERL"].ToString();
                    or1.Parameters.Add("BMVERSION", OracleType.NVarChar).Value = dwData["BMVERSION"].ToString();
                    or1.Parameters.Add("BMKGBRUTGW", OracleType.NVarChar).Value = dwData["BMKGBRUTGW"].ToString();
                    or1.Parameters.Add("BMFILLER", OracleType.NVarChar).Value = dwData["BMFILLER"].ToString();
                    or1.Parameters.Add("BMAENDZL", OracleType.NVarChar).Value = dwData["BMAENDZL"].ToString();
                    or1.Parameters.Add("BMAENDBEN", OracleType.NVarChar).Value = dwData["BMAENDBEN"].ToString();
                    or1.Parameters.Add("BMAENDDAT", OracleType.NVarChar).Value = dwData["BMAENDDAT"].ToString();
                    or1.Parameters.Add("BMNEUBEN", OracleType.NVarChar).Value = dwData["BMNEUBEN"].ToString();
                    or1.Parameters.Add("BMNEUDAT", OracleType.NVarChar).Value = dwData["BMNEUDAT"].ToString();
                    #endregion
                    break;
                case 2:
                    or1.CommandText = "UPDATE BABST SET "
                  + "BMLO=:BMLO,"
                  + "BMLB=:BMLB,"
                  + "BMLP=:BMLP,"
                  + "BMAENDBEN=:BMAENDBEN,"
                  + "BMAENDDAT=:BMAENDDAT "
                  + " WHERE  "
                  + "  BMMANDANT=:BMMANDANT AND BMBAUMKRS=:BMBAUMKRS AND BMBAUMLFD=:BMBAUMLFD";
                    or1.Parameters.Add("BMMANDANT", OracleType.NVarChar).Value = dwData["BMMANDANT"].ToString();
                    or1.Parameters.Add("BMBAUMKRS", OracleType.NVarChar).Value = dwData["BMBAUMKRS"].ToString();
                    or1.Parameters.Add("BMBAUMLFD", OracleType.NVarChar).Value = dwData["BMBAUMLFD"].ToString();
                    or1.Parameters.Add("BMLO", OracleType.NVarChar).Value = dwData["BMLO"].ToString();
                    or1.Parameters.Add("BMLB", OracleType.NVarChar).Value = dwData["BMLB"].ToString();
                    or1.Parameters.Add("BMLP", OracleType.NVarChar).Value = dwData["BMLP"].ToString();
                    or1.Parameters.Add("BMAENDBEN", OracleType.NVarChar).Value = dwData["BMAENDBEN"].ToString();
                    or1.Parameters.Add("BMAENDDAT", OracleType.NVarChar).Value = dwData["BMAENDDAT"].ToString();
                    break;
            }

            Connect2Proxy(or1);
        }
        public DataSet QueryBABST(DataRow dwData, int option = 1)
        {
            DataSet setReturn = new DataSet();
            DataSet Result = new DataSet();
            DataTable tbLocal = null;
            OracleCommand or1;
            or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 0:
                    or1.CommandText = "SELECT * FROM BABST WHERE  ROWNUM<2 ";
                    break;
                case 1:
                    or1.CommandText = "SELECT * FROM  BABST"
                        + " WHERE "
                        + " BMMANDANT=:BMMANDANT AND BMBAUMKRS=:BMBAUMKRS AND BMBAUMLFD=:BMBAUMLFD";
                    or1.Parameters.Add("BMMANDANT", OracleType.NVarChar).Value = dwData["BMMANDANT"].ToString();
                    or1.Parameters.Add("BMBAUMKRS", OracleType.NVarChar).Value = dwData["BMBAUMKRS"].ToString();
                    or1.Parameters.Add("BMBAUMLFD", OracleType.NVarChar).Value = dwData["BMBAUMLFD"].ToString();
                    break;
                case 2:
                    or1.CommandText = "SELECT * FROM  BABST"
                        + " WHERE "
                        + " BMMANDANT=:BMMANDANT AND BMAUFKRS=:BMAUFKRS AND BMAUFLFD=:BMAUFLFD AND BMAUFPOS=:BMAUFPOS"
                        + " ORDER BY 1,2,3";
                    or1.Parameters.Add("BMMANDANT", OracleType.NVarChar).Value = dwData["BMMANDANT"].ToString();
                    or1.Parameters.Add("BMAUFKRS", OracleType.NVarChar).Value = dwData["BMAUFKRS"].ToString();
                    or1.Parameters.Add("BMAUFLFD", OracleType.NVarChar).Value = dwData["BMAUFLFD"].ToString();
                    or1.Parameters.Add("BMAUFPOS", OracleType.NVarChar).Value = dwData["BMAUFPOS"].ToString();
                    break;
                case 3:
                    or1.CommandText = "SELECT * FROM  BABST"
                        + " WHERE "
                        + " BMMANDANT=:BMMANDANT AND BMAUFKRS=:BMAUFKRS AND BMAUFLFD=:BMAUFLFD ";
                    or1.Parameters.Add("BMMANDANT", OracleType.NVarChar).Value = dwData["BMMANDANT"].ToString();
                    or1.Parameters.Add("BMAUFKRS", OracleType.NVarChar).Value = dwData["BMAUFKRS"].ToString();
                    or1.Parameters.Add("BMAUFLFD", OracleType.NVarChar).Value = dwData["BMAUFLFD"].ToString();
                    break;
                case 4:
                    or1.CommandText = "SELECT * FROM  BABST "
                        + " WHERE "
                        + " BMMANDANT=:BMMANDANT AND BMKART=:BMKART AND BMKVAR=:BMKVAR AND BMFARBE=:BMFARBE ";
                    or1.Parameters.Add("BMMANDANT", OracleType.NVarChar).Value = dwData["BMMANDANT"].ToString();
                    or1.Parameters.Add("BMKART", OracleType.NVarChar).Value = dwData["BMKART"].ToString();
                    or1.Parameters.Add("BMKVAR", OracleType.NVarChar).Value = dwData["BMKVAR"].ToString();
                    or1.Parameters.Add("BMFARBE", OracleType.NVarChar).Value = dwData["BMFARBE"].ToString();
                    break;
                case 5:
                    or1.CommandText = "SELECT * FROM  BABST B JOIN BAZU Z ON BZMANDANT=BMMANDANT AND BZBAUMKRS=BMBAUMKRS AND BZBAUMLFD=BMBAUMLFD "
                        + " WHERE "
                        + " BZMANDANT=:BZMANDANT AND BZAUFKRS=:BZAUFKRS AND BZAUFLFD=:BZAUFLFD AND BZAUFPOS=:BZAUFPOS"
                        + " ORDER BY 1,2,3";
                    or1.Parameters.Add("BZMANDANT", OracleType.NVarChar).Value = dwData["BMMANDANT"].ToString();
                    or1.Parameters.Add("BZAUFKRS", OracleType.NVarChar).Value = dwData["BMAUFKRS"].ToString();
                    or1.Parameters.Add("BZAUFLFD", OracleType.NVarChar).Value = dwData["BMAUFLFD"].ToString();
                    or1.Parameters.Add("BZAUFPOS", OracleType.NVarChar).Value = dwData["BMAUFPOS"].ToString();
                    break;
                case 6:
                    or1.CommandText = "SELECT DISTINCT M.* FROM  BABST M JOIN ABPOS ON ABPMANDANT=BMMANDANT AND BMAUFKRS=ABPAUFKRS AND BMAUFLFD=ABPAUFLFD AND BMAUFPOS=ABPAUFPOS"
                        + " WHERE "
                        + " ABPMANDANT=:ABPMANDANT AND ABPAUFKRS=:ABPAUFKRS AND ABPAUFLFD=:ABPAUFLFD"
                        + " ORDER BY 1,2,3";
                    or1.Parameters.Add("ABPMANDANT", OracleType.NVarChar).Value = dwData["ABPMANDANT"].ToString();
                    or1.Parameters.Add("ABPAUFKRS", OracleType.NVarChar).Value = dwData["ABPAUFKRS"].ToString();
                    or1.Parameters.Add("ABPAUFLFD", OracleType.NVarChar).Value = dwData["ABPAUFLFD"].ToString(); 
                    break;
                default:
                    break;
            }

            Result = Connect2Proxy(or1);
            if (Result.Tables.Count > 0)
            {
                tbLocal = Result.Tables[0];
                tbLocal.TableName = "BABST";
            }
            setReturn.Merge(Result);
            return setReturn;
        }
    }
}
